package com.base.caselib.presenter;

import android.app.Activity;
import android.text.TextUtils;
import android.util.Log;

import com.base.caselib.bean.CaseDetailBean;
import com.base.caselib.bean.CaseListBean;
import com.base.caselib.view.CaseListView;
import com.base.commonlib.base.presenter.BasePresenter;
import com.base.commonlib.http.RealNetWorkUtil;
import com.base.commonlib.http.utils.CallBackImpl;
import com.base.commonlib.resh.api.RefreshLayout;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.disposables.Disposable;

/**
 * Created by Administrator on 2019/10/21.
 */

public class CaseListPresenter extends BasePresenter<CaseListView> {

    private String mKeyWord;
    private int PageIndex = 1;
    private int pageSize=10;

    public CaseListPresenter(CaseListView view, Activity activity) {
        super(view, activity);
    }

    @Override
    public void start() {
        super.start();
    }


    public void getCaseList(){
        HashMap<String, Integer> params = new HashMap<>();
        params.put("page", PageIndex);
        params.put("limit",pageSize);
        //params.put("keyWords",mKeyWord);
        //初始化控件
        mView.showPb_mes("正在渲染界面");
        Disposable disposable = RealNetWorkUtil.postContent()
                .content(params)
                .method("api-case/punishCase/getList")
                .build().enqueue(CaseListBean.class, new CallBackImpl<CaseListBean>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.hidePb_mes();
                        if (!TextUtils.isEmpty(msg)) {
                            mView.showMes(msg);
                            Log.e("json",msg);
                        }

                    }
                    @Override
                    public void onNext(CaseListBean caseListBean) {
                        mView.hidePb_mes();
                        mView.returnCaseListBean(caseListBean);
                    }
                });
        mCompositeDisposable.add(disposable);
    }


    public void onRefresh() {
        PageIndex=1;
        getCaseList();
    }

    public void onLoadMore() {
        PageIndex++;
        getCaseList();
    }


    public void steKetWord(String keyWord) {
        mCompositeDisposable.clear();
        mKeyWord=keyWord;
        PageIndex=1;
        //mView.firstLoad();
        getCaseList();

    }

}
